package com.oaker.system.service.impl;


import com.appleyk.core.ex.CommonException;
import com.appleyk.core.model.LicenseExtraParam;
import com.appleyk.core.model.LicenseResult;
import com.appleyk.core.model.LicenseVerifyManager;
import com.appleyk.verify.config.LicenseVerifyProperties;
import com.oaker.system.domain.vo.LicenseInfoVO;
import de.schlichtherle.license.LicenseContent;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LicenseServiceImpl {
    @Autowired
    private LicenseVerifyProperties properties;

    public LicenseInfoVO getLicenseInfo() throws CommonException {
        LicenseInfoVO infoVO = new LicenseInfoVO();

        LicenseVerifyManager licenseVerifyManager = new LicenseVerifyManager();

        LicenseResult verifyResult = licenseVerifyManager.verify(properties.getVerifyParam());
        if(!verifyResult.getResult()){
            throw new CommonException(verifyResult.getMessage());
        }
        LicenseContent content = verifyResult.getContent();
        LicenseExtraParam licenseCheck = (LicenseExtraParam) content.getExtra();

        BeanUtils.copyProperties(content,infoVO);
        BeanUtils.copyProperties(licenseCheck,infoVO);
        infoVO.setDescription(content.getInfo());
        return infoVO;
    }

}
